import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.configuration.file.FileConfiguration;
import rp.CMPMain;
import rp.CMDMain;
import rp.account.CMDAccount;
import rp.group.CMDGroup;
import utils.COLOR;
import utils.JDBC;
import utils.UTIL;

public class RedenPlugin extends JavaPlugin implements Listener {

    @Override
    public void onEnable() {
        saveDefaultConfig();
        FileConfiguration config = getConfig();
        saveConfig();

        JDBC jdbc = null;
        try {
            jdbc = new JDBC(config.getString("mysql.database"),config.getString("mysql.username"),config.getString("mysql.password"));
            UTIL.LOG(COLOR.RED, "数据库连接成功。");
        } catch (Exception e) {
            UTIL.LOG(COLOR.RED, "数据库连接失败，请确认已经安装MySQL并检查配置文件。");
        }
        if(jdbc==null){
            UTIL.LOG(COLOR.RED, "插件启动失败。");
            this.onDisable();
        }

        this.getCommand("r").setExecutor(new CMDMain(this,config));
        this.getCommand("account").setExecutor(new CMDAccount(this,config,jdbc));
        //this.getCommand("group").setExecutor(new CMDGroup(this,config));
        UTIL.LOG(COLOR.CYAN, "插件已开启。");
    }

    @Override
    public void onDisable() {
        UTIL.LOG(COLOR.CYAN,"插件已关闭。");
    }

    @Override
    public void onLoad() {

    }

}
